package org.dromara.xhlj.crud.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import org.dromara.common.satoken.utils.LoginHelper;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.xhlj.domain.vo.XhljSignVo;
import org.dromara.xhlj.domain.query.XhljSignQuery;
import org.dromara.xhlj.domain.bo.XhljSignBo;
import org.dromara.xhlj.crud.service.IXhljSignCrudService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * xhlj-crud-大会签到
 *
 * @author yf
 * @date 2024-07-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xhlj/sign")
public class XhljSignCrudController extends BaseController {

    private final IXhljSignCrudService xhljSignService;

    /**
     * 分页查询大会签到列表
     */
    @SaCheckPermission("xhlj:sign:list")
    @GetMapping("/list")
    public TableDataInfo<XhljSignVo> list(XhljSignQuery query, PageQuery pageQuery) {
         return xhljSignService.queryPageList(query, pageQuery);
    }

    /**
     * 查询大会签到列表
     */
    @SaCheckPermission("xhlj:sign:list")
    @GetMapping("/allList")
    public TableDataInfo<XhljSignVo> allList(XhljSignQuery query) {
        List<XhljSignVo> list =  xhljSignService.queryList(query);
        return TableDataInfo.build(list);
    }


    /**
     * 导出大会签到列表
     */
    @SaCheckPermission("xhlj:sign:export")
    @Log(title = "大会签到", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(XhljSignQuery query, HttpServletResponse response) {
        List<XhljSignVo> list = xhljSignService.queryList(query);
        ExcelUtil.exportExcel(list, "大会签到", XhljSignVo.class, response);
    }

    /**
     * 获取大会签到详细信息
     *
     * @param signId 主键
     */
    @SaCheckPermission("xhlj:sign:query")
    @GetMapping("/{signId}")
    public R<XhljSignVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Integer signId) {
        return R.ok(xhljSignService.queryById(signId));
    }

    /**
     * 新增大会签到
     */
    @SaCheckPermission("xhlj:sign:add")
    @Log(title = "大会签到", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody XhljSignBo bo) {
        bo.setCreateBy(Math.toIntExact(LoginHelper.getUserId()));
        return toAjax(xhljSignService.insertByBo(bo));
    }

    /**
     * 修改大会签到
     */
    @SaCheckPermission("xhlj:sign:edit")
    @Log(title = "大会签到", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody XhljSignBo bo) {
        return toAjax(xhljSignService.updateByBo(bo));
    }

    /**
     * 删除大会签到
     *
     * @param signIds 主键串
     */
    @SaCheckPermission("xhlj:sign:remove")
    @Log(title = "大会签到", businessType = BusinessType.DELETE)
    @DeleteMapping("/{signIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Integer[] signIds) {
        return toAjax(xhljSignService.deleteWithValidByIds(List.of(signIds), true));
    }
}
